<?
define("NO_KEEP_STATISTIC", true);
define("NO_AGENT_STATISTIC", true);
define("NO_LANG_FILES", true);
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");

/*$path = str_replace(array("\\", "//"), "/", dirname(__FILE__)."/lang/en/add_message.php");
@include_once($path);
$path = str_replace(array("\\", "//"), "/", dirname(__FILE__)."/lang/".LANGUAGE_ID."/add_message.php");
@include_once($path);*/

if (!CModule::IncludeModule("consult"))
	echo "Module not installed";

if(CModule::IncludeModule("compression"))
	Ccompress::Disable2048Spaces();


if (!check_bitrix_sessid())
{
	echo "Session expired!";
}
else
{
	$message = $_REQUEST["data"];
	CUtil::decodeURIComponent($message);
	$message = Trim($message);
	if (StrLen($message) <= 0)
	{
		echo "Message is empty";
	}
	else
	{
		$OWNER_ID = intval ($_REQUEST["user_id"]);
		$STREAM_ID = intval ($_REQUEST["stream_id"]);
		if ($OWNER_ID > 0 && $OWNER_ID > 0)
		{
			$obmess = new COnline_message;
			$arAdd = array(
				"OWNER_ID" => $OWNER_ID,
				"STREAM_ID" => $STREAM_ID,
				"MESSAGE" => $message
			);
			if (!$obmess->Add($arAdd))
			{
				echo $obmess->LAST_ERROR;
			}
		}
		else
		{
			echo "Error params for add";
		}
	}
}
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");
?>